package com.ibiaoke.order.dao;

import com.ibiaoke.common.base.BaseDao;
import com.ibiaoke.common.consts.CommonConsts;
import com.ibiaoke.order.entity.OrderAddress;
import com.ibiaoke.order.entity.OrderAddressExample;
import com.ibiaoke.order.mapper.OrderAddressMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * Created by huhaichao on 2017/6/8.
 */
@Repository
public class OrderAddressDao extends BaseDao<OrderAddress, OrderAddressExample, Integer, OrderAddressMapper> {

    @Autowired
    private OrderAddressMapper orderAddressMapper;

    @Override
    public OrderAddressMapper getMapper() {
        return orderAddressMapper;
    }


    public List<OrderAddress> listOrderAddress(Integer customerId) {

        OrderAddressExample example = new OrderAddressExample();
        example.createCriteria().andDelStatusEqualTo((byte) CommonConsts.NO)
                .andUserIdEqualTo(customerId);
        return orderAddressMapper.selectByExample(example);
    }

    public int delete(Integer addressId) {
        OrderAddress orderAddress = new OrderAddress();
        orderAddress.setAddressId(addressId);
        orderAddress.setDelStatus((byte) CommonConsts.YES);
        orderAddress.setUpdateTime(new Date());
        return updateByPrimaryKeySelective(orderAddress);
    }
}
